using System;
using System.Windows.Media;

namespace Crusades.Extensions{
  public static class ColorExtensions {
    public static Color FromHexString(this string hexValues) {
      if(hexValues[0]=='#') hexValues =  hexValues.Remove(0, 1);
      if (hexValues.Length != 8) {
        throw new Exception("Hex string must contain 8 characters\n" + hexValues + " is invalid.");
      }

      byte a = Convert.ToByte(hexValues.Substring(0, 2), 16);
      byte r = Convert.ToByte(hexValues.Substring(2, 2), 16);
      byte g = Convert.ToByte(hexValues.Substring(4, 2), 16);
      byte b = Convert.ToByte(hexValues.Substring(6, 2), 16);
      return Color.FromArgb(a, r, g, b);
    }
  }
}